package com.aigou.admin.aigouspringboot.controller.user;

import com.aigou.admin.aigouspringboot.common.LogScope;
import com.aigou.admin.aigouspringboot.entity.Product;
import com.aigou.admin.aigouspringboot.entity.dto.ProductQueryDTO;
import com.aigou.admin.aigouspringboot.result.Result;
import com.aigou.admin.aigouspringboot.service.ProductService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("userProductController")
@RequestMapping("/user/product")
@Slf4j
public class ProductController {

    @Resource
    private ProductService productService;



    @GetMapping("/userProductType")
    @Cacheable(cacheNames = "importer")
    public Result userProductType() {
        List<Product> products = productService.selectAllByProductType();
        return Result.success(products);
    }

    @GetMapping("/userProductTypeFuShi")
    @Cacheable(cacheNames = "costume")
    public Result userProductTypeFuShi() {
        List<Product> products = productService.selectAllByProductTypeFuShi();
        return Result.success(products);
    }

    @GetMapping("/userProductTypeMeiZhuang")
    @Cacheable(cacheNames = "beautyMakeup")
    public Result userProductTypeMeiZhuang() {
        List<Product> products = productService.selectAllByProductTypeMeiZhuang();
        return Result.success(products);
    }

    @GetMapping("/userProductTypeBook")
    @Cacheable(cacheNames = "book")
    public Result userProductTypeBook() {
        List<Product> products = productService.selectAllByProductTypeBook();
        return Result.success(products);
    }

    @GetMapping("/selectProductTypeID")
    public Result selectProductByProductTypeID(String productTypeID) {
        List<Product> products = productService.selectProductByProductTypeID(productTypeID);
        return Result.success(products);
    }

    @GetMapping("/{id}")
    @LogScope(title = "产品管理模块", content = "根据id查询产品信息")
    public Result detail(@PathVariable String id) {

        Product product = productService.selectById(id);
        return Result.success(product);
    }

    @GetMapping
    @LogScope(title = "产品管理模块", content = "查看产品列表信息")
    public Result select(@RequestParam Integer current, ProductQueryDTO productQueryDTO) {

        log.info("查询第{}页的产品信息", current);
        // 分页查询，返回PageInfo（分页插件工具）
        PageInfo<Product> productPageInfo = productService.selectProductListByPage(current,productQueryDTO);
        return Result.success(productPageInfo);
    }

    @GetMapping("/createTime")
    @LogScope(title = "产品管理模块", content = "查看产品列表信息")
    public Result selectByTime() {
        List<Product> product = productService.selectByTime();
        return Result.success(product);
    }

}
